package leetcode;

/**
 * Created with IntelliJ IDEA.
 * Description:206. 反转链表
 * User: 东莞呵呵
 * Date:2022-07-10
 * Time:8:14
 */
public class TestDemo1 {
    public static void main(String[] args) {

    }
    public ListNode reverseList(ListNode head) {
        if(head==null){
            return null;
        }else if(head.next==null){
            return head;
        }

        ListNode cur = head.next;
        ListNode curNext=cur.next;
        cur.next=head;
        head.next=null;
        head=cur;
        cur=curNext;
        while(cur!=null){
            curNext=cur.next;
            cur.next=head;
            head=cur;
            cur=curNext;
        }
        return head;
    }
}
 class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
